package cn.com.eado.crm.m.db

import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

@Entity(tableName = "province")
@TypeConverters(Province.Converters::class)
data class Province(
    @PrimaryKey(autoGenerate = true)
    val id: Int,
    val provinceName: String,
    val citys : List<City>
){
    data class City(
        val citysName: String
    )

    class Converters{
        @TypeConverter
        fun stringToObject(value: String): List<City> {
            val listType = object : TypeToken<List<City>>() {
            }.type
            return Gson().fromJson(value, listType)
        }

        @TypeConverter
        fun objectToString(list: List<City>): String {
            val gson = Gson()
            return gson.toJson(list)
        }
    }
}